number= input ()
 
if len(str(number)) != 4:
    print(0)
else:
    prime = False
    for length in range(4, 0, -1):
        if prime:
            break
        for i in range(4 - length + 1):
            h = int(str(number)[i:i+length])
            if h < 2:
                continue
            for j in range(2, int(h**0.5) + 1):
                if h % j == 0:
                    break
            else:
                print(h)
                prime = True
                break
    if not prime:
        print(0)
